<?php
namespace App\Admin\Actions\Grid;

use Dcat\Admin\Grid\BatchAction;
use App\Admin\Forms\ShopGoodsTransferForm;
use Dcat\Admin\Widgets\Modal;

class GoodsTransferAction extends BatchAction{
    /**
     * @return string
     */
    protected $title = '批量转移分类';

    /**
     * Handle the action request.
     *
     * @param Request $request
     *
     * @return Response
     */

    public function render()
    {
        // 实例化表单类并传递自定义参数
        $form = ShopGoodsTransferForm::make();

        return Modal::make()
            ->lg()
            ->title($this->title)
            ->body($form)
            ->onLoad($this->getModalScript())
            ->button($this->title);
    }


    protected function getModalScript()
    {
        // 弹窗显示后往隐藏的id表单中写入批量选中的行ID
        return <<<JS
// 获取选中的ID数组
var key = {$this->getSelectedKeysScript()}
//batchsp-id 与 之前弹窗隐藏的绑定的id一致
$('#transfer-goods-ids').val(key);
JS;
    }
}
